<template>
    <div class="add-page">
        <!-- Header -->
        <Header title="编辑地址">
            <template v-slot:back>
                <span @click="$router.go(-1)">&lt;</span>
            </template>
            <template v-slot:ope>
                
            </template>
        </Header>
        
        <!-- 表单 -->
        <div class="form">
            <div class="cell">
                <div class="label">联系人</div>
                <input type="text" placeholder="姓名" v-model="name">
            </div>
            <div class="cell">
                <div class="label">电话</div>
                <input type="text" placeholder="手机号码" v-model="phone">
            </div>
            <div class="cell">
                <div class="label">地址</div>
                <input type="text" placeholder="地址" v-model="address">
            </div>
        </div>

        <!-- 按钮 -->
        <div class="btn-box">
            <div class="btn" @click="delete_address(id)">删除</div>
            <div class="btn" @click="edit_address($data)">保存</div>
        </div>
    </div>
</template>

<script>
import {mapMutations} from 'vuex'

export default {
    data(){
        return {
            name:"",//联系人
            address:'',//地址
            phone:'',//手机号
            id:0,//地址的id
        }
    },
    mounted(){
        console.log(this.$route.params.item);
        
        //保存"点击编辑"时传来的地址数据
        this.name = this.$route.params.item.name;
        this.address = this.$route.params.item.address;
        this.phone = this.$route.params.item.phone;
        this.id = this.$route.params.item.id;
    },
    methods:{
        ...mapMutations(['delete_address','edit_address'])
    }
}
</script>
<style scoped >
.form .cell{
    display: flex;
    margin: 30px  20px;
}
.form .cell .label{
    width: 60px;
    margin-right: 20px;
}
.form .cell input{
    flex: 1;
    outline: none;
    border:none;
}
.btn-box{
    margin: 20px;
    display: flex;
}
.btn-box .btn{
    width: 50%;
   
    line-height: 50px;
    text-align: center;
    color: white;
    background-color: lightskyblue;
}
.btn-box .btn:first-child{
     margin-right: 20px;
}
</style>